// pages/videodetail/videodetail.js
var api = require('../../utils/api.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:{
      'vid':'',
      'name':'',
      'average':'',
      'path':''
    },
    myScore:{
      'score':'',
      'comment':'',
      'status':''
    },
    lists:[],
    count:'',
    apptoken:'',
    vid:'',
    isEnable:false,
    scrollheight:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      vid: options.vid
    })
    try {
      var value = wx.getStorageSync('token')
      if (value) {
        that.setData({
          apptoken: value
        })
      }
    } catch (e) {
    }
    wx.getSystemInfo({
      success: function (res) {
        var pix = res.windowWidth/750;
        that.setData({
          scrollheight:(res.windowHeight/pix-690)
        });
      }
    });
    this.videoDetailRequest();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var valuestatus = app.status;
    if (valuestatus == 1) {
      this.setData({
        isEnable: true
      })
    } else {
      this.setData({
        isEnable: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  videoDetailRequest() {
    var that = this;
    api.post({
      url: 'Video/browse',
      data: {
        'token': that.data.apptoken,
        'vid': that.data.vid,
      },
      success: data => {
        if (data.code == 200) {
          that.setData({
            info: data.data.info,
            myScore: data.data.myScore,
            lists: data.data.lists,
            count:data.data.count
          })
          if(data.data.myScore.status == 1){
            that.setData({
              isEnable:true
            })
          } else {
            that.setData({
              btntext: false
            })
          }
        } else if (data.code == 300) {
          wx.showToast({
            title: data.data.message,
            icon: 'none'
          })
        } else if (data.code == 400) {
          wx.showToast({
            title: data.data.message,
            icon: 'none'
          })
        }
      }
    })
  }
})